﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.ObjectBuilder;
using Microsoft.Practices.ObjectBuilder2;

namespace IoCNamed.UnityNameResolver
{
    public class NameResolverExtension : UnityContainerExtension, INameResolverExtensionConfigurator
    {
        public INameResolverExtensionConfigurator RegisterDelegatedName<TTypeToBuild>(NameResolverDelegate resolver)
        {
            Context.Policies.Set<IResolveNamePolicy>(
                new ResolveNamePolicyDelegated(resolver),
                NamedTypeBuildKey.Make<TTypeToBuild>());

            return this;
        }

        protected override void Initialize()
        {
            Context.Strategies.AddNew<ResolveNameBuilderStrategy>(UnityBuildStage.Setup);
        }

        public NameResolverExtension()
            : base()
        {
        }
    }
}
